2020-2021 Sunseeker Telemetry and Lighting System
comp_d_ex1_outputToggleVcompVsVref2V.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430FR57xx Demo - COMPD Toggle from LPM4; input channel CD13;
34 // Vcompare is compared against the internal reference 2.0V
35 //
36 // Description: Use CompD (input channel CD13) and internal reference to
37 // determine if input'Vcompare'is high or low. When Vcompare exceeds 2.0V
38 // CDOUT goes high and when Vcompare is less than 2.0V then CDOUT goes low.
39 // P3.5/CDOUT is connected internally to an LED; it will toggle accordingly.
40 //
41 // MSP430FR5739
42 // ------------------
43 // /|\| |
44 // | | |
45 // --|RST P1.2/CD2|<--Vcompare
46 // | |
47 // | P3.5/CDOUT|----> 'high'(Vcompare>2.0V); 'low'(Vcompare<2.0V)
48 // | | |
49 // | | | LED 'ON'(Vcompare>2.0V); 'OFF'(Vcompare<2.0V)
50 // | |
51 //
52 //******************************************************************************
53 #include "driverlib.h"
54 
55 void main(void)
56 {
57  //Stop WDT
58  WDT_A_hold(WDT_A_BASE);
59 
60  //Set P3.5 as Ternary Module Function Output.
61  /*
62 
63  * Select Port 3
64  * Set Pin 5 to output Ternary Module Function, (CBOUT).
65  */
66  GPIO_setAsPeripheralModuleFunctionOutputPin(
67  GPIO_PORT_P3,
68  GPIO_PIN5,
69  GPIO_TERNARY_MODULE_FUNCTION
70  );
71 
72  //Initialize the Comparator D module
73  /* Base Address of Comparator D,
74  * Pin CD2 to Positive(+) Terminal,
75  * Reference Voltage to Negative(-) Terminal,
76  * Normal Power Mode,
77  * Output Filter On with minimal delay,
78  * Non-Inverted Output Polarity
79  */
80 
81  Comp_D_initParam param = {0};
82  param.positiveTerminalInput = COMP_D_INPUT2;
83  param.negativeTerminalInput = COMP_D_VREF;
84  param.outputFilterEnableAndDelayLevel = COMP_D_FILTEROUTPUT_OFF;
85  param.invertedOutputPolarity = COMP_D_NORMALOUTPUTPOLARITY;
86  Comp_D_init(COMP_D_BASE, &param);
87 
88  //Set the reference voltage that is being supplied to the (-) terminal
89  /* Base Address of Comparator D,
90  * Reference Voltage of 2.0 V,
91  * Lower Limit of 2.0*(32/32) = 2.0V,
92  * Upper Limit of 2.0*(32/32) = 2.0V
93  */
94  Comp_D_setReferenceVoltage(COMP_D_BASE,
95  COMP_D_VREFBASE2_0V,
96  32,
97  32
98  );
99 
100  //Disable Input Buffer on P1.2/CD2
101  /* Base Address of Comparator D,
102  * Input Buffer port
103  * Selecting the CDx input pin to the comparator
104  * multiplexer with the CDx bits automatically
105  * disables output driver and input buffer for
106  * that pin, regardless of the state of the
107  * associated CDPD.x bit
108  */
109  Comp_D_disableInputBuffer(COMP_D_BASE,
110  COMP_D_INPUT2);
111 
112  //Allow power to Comparator module
113  Comp_D_enable(COMP_D_BASE);
114 
115  __delay_cycles(400); // delay for the reference to settle
116 
117  __bis_SR_register(LPM4_bits); // Enter LPM4
118  __no_operation(); // For debug
119 }
MPU_initThreeSegmentsParam param
__no_operation()
__delay_cycles(500000)